package com.carleasoft.mps.adu.business.user.controller;

import java.text.ParseException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.adu.business.user.bean.entity.MAuthorityUserDynamic;
import com.carleasoft.mps.adu.business.user.bean.po.MAuthorityUserDynamicPo;
import com.carleasoft.mps.adu.business.user.bean.vo.MAuthorityDeptCountVo;
import com.carleasoft.mps.adu.business.user.bean.vo.MAuthorityUserDynamicVo;
import com.carleasoft.mps.core.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.carleasoft.mps.adu.business.user.service.IMAuthorityUserDynamicService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 人员动态Controller
 * 
 * @author yiSl
 * @date 2024-04-12
 */
@RestController
@RequestMapping("/userDynamic")
public class MAuthorityUserDynamicController
{
    @Autowired
    private IMAuthorityUserDynamicService mAuthorityUserDynamicService;

    /**
     * 查询人员动态列表
     */
    @PostMapping("/list")
    public R list(@RequestBody MAuthorityUserDynamicPo mAuthorityUserDynamicPo)
    {
        Page<MAuthorityUserDynamicVo> list = mAuthorityUserDynamicService.selectMAuthorityUserDynamicList(new Page(mAuthorityUserDynamicPo.getCurrent(), mAuthorityUserDynamicPo.getSize()),mAuthorityUserDynamicPo);
        return R.ok(list);
    }

    /**
     * 导入人员动态
     * @param file
     * @return
     */
    @PostMapping("/importUserDynamicExcel")
    public R importUserDynamicExcel(@RequestPart("file") MultipartFile file) {
        boolean isOk = mAuthorityUserDynamicService.userDynamicExcel(file);
        return R.ok(isOk);
    }


    /**
     * 人员动态导出
     * @param startTime
     * @param response
     * @return
     */
    @PostMapping("/exportUserDynamicExcel")
    public R<Boolean> export(@RequestPart("startTime") String startTime, HttpServletResponse response) {
        return R.ok(mAuthorityUserDynamicService.export(startTime,response));
    }

    /**
     * 获取人员动态详细信息
     */
    @PostMapping("/getById")
    public R getInfo(@RequestBody MAuthorityUserDynamicPo mAuthorityUserDynamicPo)
    {
        return R.ok(mAuthorityUserDynamicService.selectMAuthorityUserDynamicById(mAuthorityUserDynamicPo.getId()));
    }

    /**
     * 新增人员动态
     */
    @PostMapping("/add")
    public R add(@RequestBody MAuthorityUserDynamic mAuthorityUserDynamic)
    {
        return R.ok(mAuthorityUserDynamicService.insertMAuthorityUserDynamic(mAuthorityUserDynamic));
    }

    /**
     * 根据部门CODE分组求和轮休总数
     */
    @PostMapping("/deptCount")
    public R deptCount()
    {
        List<MAuthorityDeptCountVo> list = mAuthorityUserDynamicService.selectMAuthorityDeptCountByDeptCode();
        return R.ok(list);
    }

    /**
     * 修改人员动态
     */
    @PostMapping("/update")
    public R edit(@RequestBody MAuthorityUserDynamic mAuthorityUserDynamic)
    {
        return R.ok(mAuthorityUserDynamicService.updateMAuthorityUserDynamic(mAuthorityUserDynamic));
    }

    /**
     * 删除人员动态
     */
	@PostMapping("/delete")
    public R remove(@RequestBody MAuthorityUserDynamic mAuthorityUserDynamic)
    {
        return R.ok(mAuthorityUserDynamicService.deleteMAuthorityUserDynamicById(mAuthorityUserDynamic.getId()));
    }
}
